function(update_data_file_package _NAME _FOLDER _FILES)
	message(STATUS "Updating data files package...")

	# Get FTP credentials needed for upload
	if(NOT EXISTS @UploadAssets_FTP_CREDENTIALS_FILE@)
		message("FTP credentials are missing at @UploadAssets_FTP_CREDENTIALS_FILE@.")
		message(STATUS "...aborting data file packaging.")
		return()
	endif()
	
	file (STRINGS "@UploadAssets_FTP_CREDENTIALS_FILE@" FTP_CREDENTIALS)

	list(GET FTP_CREDENTIALS 0 FTP_URL)
	list(GET FTP_CREDENTIALS 1 FTP_USER)
	list(GET FTP_CREDENTIALS 2 FTP_PW)
	
	# Get current version
	set(REQUESTED_VERSION_FILE ${_FOLDER}/.reqversion)
	set(CURRENT_VERSION_FILE ${_FOLDER}/.version)

	file (STRINGS ${REQUESTED_VERSION_FILE} CURRENT_VERSION_NUM)
	math(EXPR NEW_VERSION_NUM "${CURRENT_VERSION_NUM}+1")
	
	# Clean and create a temporary folder
	execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory @UploadAssets_TEMP_FOLDER@)	
	execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory @UploadAssets_TEMP_FOLDER@)	

	# Update version number in the package
	file(WRITE ${CURRENT_VERSION_FILE} ${NEW_VERSION_NUM})
	
	# Generate an archive with data files
	set(ARCHIVE_FILENAME ${_NAME}_${NEW_VERSION_NUM}.zip)
	set(ARCHIVE_PATH @UploadAssets_TEMP_FOLDER@/${ARCHIVE_FILENAME})

	execute_process(
		COMMAND
			${CMAKE_COMMAND} -E tar
			"cf" "${ARCHIVE_PATH}" --format=zip
		    --files-from=${_FOLDER}/${_FILES}
		WORKING_DIRECTORY "${_FOLDER}/.."
		RESULT_VARIABLE ARCHIVE_STATUS_CODE
		ERROR_VARIABLE ARCHIVE_ERROR_MESSAGE
	)

	if(NOT ARCHIVE_STATUS_CODE EQUAL 0)
		message("Failed to create archive file: ${ARCHIVE_PATH}. Error: ${ARCHIVE_ERROR_MESSAGE}")
		message(STATUS "...aborting data file packaging.")
		return()
	endif()
	
	# Upload the package
	message(STATUS "   Uploading data package: ${ARCHIVE_FILENAME}")
	file(
		UPLOAD "${ARCHIVE_PATH}" "${FTP_URL}/${ARCHIVE_FILENAME}"
		USERPWD ${FTP_USER}:${FTP_PW}
		STATUS UPLOAD_STATUS_CODE
		SHOW_PROGRESS)
		
	if(NOT UPLOAD_STATUS_CODE EQUAL 0)
		message("Failed to upload file: ${ARCHIVE_PATH}. Error code: ${UPLOAD_STATUS_CODE}")
		message(STATUS "...aborting data file packaging.")
	endif()

	# Update active version number (only if everything else succeeds)
	file(WRITE ${REQUESTED_VERSION_FILE} ${NEW_VERSION_NUM})

	# Clean up
	execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory @UploadAssets_TEMP_FOLDER@)
	
	message(STATUS "...data file packaging succesful, new version is ${NEW_VERSION_NUM}.")
endfunction()

update_data_file_package(@UploadAssets_ARCHIVE_NAME@ @UploadAssets_INPUT_FOLDER@ @UploadAssets_INPUT_FILES@)
